package and.booze.now;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;

public class Settings extends Activity {
	
	//Declarations
	private EditText editTextPlayers;
	private EditText editTextDrinks;
	private EditText editTextSlugs;
	private EditText editTextTime;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        //loads shared preferences
        SharedPreferences settings = getSharedPreferences("BoozePreferences", 0);
        
        //Loads players
        String players = settings.getString("players", "");
        editTextPlayers = (EditText) findViewById(R.id.editboxPlayer);
        editTextPlayers.setText(players);
        
        //Loads drinks
        String drinks = settings.getString("drinks", "");
        editTextDrinks = (EditText) findViewById(R.id.editboxDrinks);
        editTextDrinks.setText(drinks);

        //Loads slugs count
        int slugs = settings.getInt("slugs", 0);
        editTextSlugs = (EditText) findViewById(R.id.editboxSlugs);
        editTextSlugs.setText(Integer.toString(slugs));
        
        //Loads time
        int time = settings.getInt("time", 180);
        editTextTime = (EditText) findViewById(R.id.editboxTime);
        editTextTime.setText(Integer.toString(time));
    }
    
    /** Called when the activity was closed. */
    @Override
    public void onStop()
    {
    	super.onStop();
    	Log.d("test","stop");
    	SharedPreferences settings = getSharedPreferences("BoozePreferences", 0);
    	SharedPreferences.Editor editor= settings.edit();
    	editor.putString("players", editTextPlayers.getText().toString());
    	editor.putString("drinks", editTextDrinks.getText().toString());
    	editor.putInt("slugs", Integer.parseInt(editTextSlugs.getText().toString()));
    	editor.putInt("time", Integer.parseInt(editTextTime.getText().toString()));
    	editor.commit();
    }
    
    
}